<template>
	<view>
		<uniNavBar
		title='支付'
		left-text='关闭'
		fixed='true'
		status-bar='true'
		@clickLeft='goBack'
		></uniNavBar>
		<view class="pay-main">
			<label for="">
				<view class="pay-item">
					<image class="pay-img" src="@/static/alipay.jpg" mode=""></image>
					<view>
						<view>支付宝支付</view>
						<view class="pay-text">推荐支付宝用户使用</view>
					</view>
					<label class="radio">
						<radio value="" color="#ff3333" /><text></text>
					</label>
				</view>
			</label>
			<label for="">
				<view class="pay-item">
					<image class="pay-img" src="@/static/wx.jpg" mode=""></image>
					<view>
						<view>微信支付</view>
						<view class="pay-text">推荐微信用户使用</view>
					</view>
					<label class="radio">
						<radio value="" color="#ff3333" /><text></text>
					</label>
				</view>
			</label>
		</view>
		<!--去支付-->
		<view class="pay-foot">
			<view class="total">
				<text>合计</text>
				<text>￥{{totalPrice}}</text>
			</view>
			<view class="go-pay" @click="goPay">去支付</view>
		</view>
	</view>
</template>

<script>
	import config from '@/config'; // 引入config来设置全局的东西
	import uniNavBar from '@/components/uni/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'  
		export default {  
			components: {  
				uniNavBar, // 注册组件  
			},  
			data() {  
				return {  
					 totalPrice: '',
				}  
			},  
			 mounted() {
			    this.getTotalPrice(); // 在页面加载时获取总价
			  },
			computed:{
			},
			methods: {
				//点击关闭，返回上一页
				getTotalPrice() {
				      this.totalPrice = uni.getStorageSync('totalPrice');
					  console.log("总金额："+this.totalPrice);
				    },
				goBack(){
					uni.navigateBack({
						delta:1
					})
				},
				goPay(){
					uni.reLaunch({
						url:"/pages/pay/pay-success"
					});
					 this.updateUserType();
				},
				updateUserType() {
				  uni.request({
				    url: config.apiUrl + '/user/updateusertype',
				    method: 'POST',
				    header: {
				      'Content-Type': 'application/json'
				    },
				    data: JSON.stringify({
				      userType: '01', // 更新为会员类型
				    
				    }),
				    success: (response) => {
				      if (response.data.success) {
				        // 支付成功，更新用户类型成功
				        uni.showToast({
				          title: '支付成功，用户类型已更新',
				          icon: 'success'
				        });
						uni.reLaunch({
							url:'/pages/pay/payvip-success'
						})
				        // 可以在这里进行页面跳转或其他逻辑
				      } 
										  },
				    fail: (err) => {
				      // 处理请求失败的情况
				      uni.showToast({
				        title: '请求失败，请稍后再试',
				        icon: 'none'
				      });
				    }
				  });
				}

		} 
		}
</script>

<style scoped>
	.pay-main{
		height: 1200rpx;
		background-color: #FFEFBA;
	}
.pay-item{
	display: flex;
	justify-content: space-between;
	align-items:center;
	padding: 20rpx;
	border-bottom: 2rpx solid #cccccc;
	background-color: #FFEFBA;
}
.pay-text{
	color: darkgray;
	margin-top: 10rpx;
}
.pay-img{
	width: 100rpx;
	height: 100rpx;
}
.pay-foot{
	display: flex;
	justify-content: space-between;
	position: fixed;
	left: 0;
	bottom: 0;
	height: 100rpx;
	align-items: center;
	width: 100%;
}
.total{
	line-height: 100rpx;
	color: #ffffff;
	flex: 1;
	background-color: #000000;
	padding-left: 100rpx;
}
.go-pay{
	line-height: 100rpx;
	text-align: center;
	width: 220rpx;
	color: #ffffff;
	background-color: #EACD6F;
}
</style>